package martin.tpfinal.common.data;

import java.util.Iterator;
import java.util.Map;

public class Constantes {

	/*
	  	asegura -> 	0.0 0.0 0.0	
		bajar -> 	0.0 0.0 1.0	
		subir -> 	0.0 1.0 0.0	
		persiana -> 0.0 1.0 1.0	
		luces -> 	1.0 1.0 1.0	
	 */
	
	public static final String PERSIANA_STRING="persiana";
	public static final double[] PERSIANA_DOUBLE={0.0,1.0,1.0};

	public static final String LUZ_STRING="luz";
	public static final double[] LUZ_DOUBLE={1.0,1.0,1.0};

	public static final String SUBIR_STRING="subir";
	public static final double[] SUBIR_DOUBLE={0.0,1.0,0.0};

	public static final String BAJAR_STRING="bajar";
	public static final double[] BAJAR_DOUBLE={0.0,0.0,1.0};

	public static final String ASEGURA_STRING="asegura";
	public static final double[] ASEGURA_DOUBLE={0.0,0.0,0.0};
	
	public static final String NO_ENCONTRO="noEncontro";
	public static final double[] NO_ENCONTRO_DOUBLE={-1.0,-1.0,-1.0};
	
	public static final String ERROR_STRING="error";
	public static final double[] ERROR_DOUBLE={-2.0,-2.0,-2.0};
	
	public static Map<String, double[]> palabras;
	
	static{
			palabras.put(PERSIANA_STRING,PERSIANA_DOUBLE);
			palabras.put(LUZ_STRING,LUZ_DOUBLE);
			palabras.put(SUBIR_STRING,SUBIR_DOUBLE);
			palabras.put(BAJAR_STRING,BAJAR_DOUBLE);
			palabras.put(ASEGURA_STRING,ASEGURA_DOUBLE);
			palabras.put(ERROR_STRING,ERROR_DOUBLE);
	}
	
	
	
	public static String getStringOfDouble(double[] entrada){
		
		boolean encontro=false;
		Iterator<Map.Entry<String,double[]>> itPalabras=palabras.entrySet().iterator();
		
		while (itPalabras.hasNext()){
			Map.Entry<String,double[]> palabraEntry = itPalabras.next();
			
			double[] palabra = palabraEntry.getValue();
			
			for (int j=0;j<palabra.length;j++){
				if (palabra[j]==entrada[j]){
					encontro=true;
				}
				else {
					encontro=false;
					break;
				}
			}
			
			if (encontro)
				return palabraEntry.getKey();
	 
		}
	
		return NO_ENCONTRO ;
	} 
	
	public static double[] getDoubleOfString(String palabra){
		
		if (palabras.containsKey(palabra))
			return palabras.get(palabra);
		
		return palabras.get(NO_ENCONTRO) ;

	}

	public static boolean exitoso(String valor) {
		if (valor.equals(NO_ENCONTRO) || valor.equals(ERROR_STRING))
			return false;
		return true;
	} 

	
}
